/*
 * @Author: lihaogn
 * @Date: 2021-12-11 23:32:51
 * @LastEditTime: 2021-12-19 21:14:33
 * @LastEditor: lihaogn
 * @Description: user 用户迁移文件
 *   创建迁移文件：npx sequelize migration:generate --name=init-users
 *   运行迁移文件：npx sequelize db:migrate
 *   撤销迁移文件：npx sequelize-cli db:migrate:undo:all --to 20211211153251-init-users.js
 * @FilePath: \Lix-admin-server\database\migrations\20211211153251-init-users.js
 */
"use strict";
const { getUsername } = require("../../app/utils/commonUtils");
module.exports = {
  up: async (queryInterface, Sequelize) => {
    /**
     * Add altering commands here.
     * 在执行数据库升级时调用的函数
     *
     * Example:
     * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
     */

    const { TINYINT, DATE, STRING } = Sequelize;
    await queryInterface.createTable("users", {
      id: { type: STRING(40), primaryKey: true },
      name: {
        type: STRING(20),
        allowNull: false,
        defaultValue: getUsername(),
        unique: "uk_user_name",
      },
      realname: {
        type: STRING(20),
      },
      password: {
        type: STRING(40),
        allowNull: false,
        defaultValue: "123456",
      },
      mobile: { type: STRING(15) },
      email: { type: STRING(255) },
      // 1-启用，2-停用，3-注销
      status: { type: TINYINT, allowNull: false },
      createdAt: { type: DATE, field: "created_at" },
      updatedAt: { type: "TIMESTAMP", field: "updated_at" },
    });
  },

  down: async (queryInterface, Sequelize) => {
    /**
     * Add reverting commands here.
     * 在执行数据库降级时调用的函数
     *
     * Example:
     * await queryInterface.dropTable('users');
     */

    await queryInterface.dropTable("users");
  },
};
